{% extends "cms/cms_book.html" %}

{% block book_body %}
    <h5 class="text-center">图书信息</h5>
    <form class="col-8">
        <label>
            <select class="form-control" name="board_id">
{#                    <option value="{{ 0 }}">全部数据</option>#}
                {% for board in boards %}
                    {% if board.id == current_board_id %}
                        <option value="{{ board.id }}" selected>{{ board.name }}</option>
                    {% endif %}
                    <option  value="{{ board.id }}">{{ board.name }}</option>
                {% endfor %}
            </select>
        </label>
        <button type="submit" class="btn btn-primary">过滤</button>
    </form>
    <table class="table">
      <thead>
        <tr>
          <th scope="col">图书名</th>
          <th scope="col">作者</th>
          <th scope="col">分类</th>
          <th scope="col">状态</th>
          <th scope="col">操作</th>
        </tr>
      </thead>
      <tbody>
        {% for book in books %}
            <tr>
                <td>{{ book.name }}</td>
                <td>{{ book.author_name }}</td>
                <td>{{ book.board.name }}</td>
                <td>
                    {% if book.is_borrowed %}
                        <span class="text-danger">已借出</span>
                    {% else %}
                        <span class="text-success">在图书馆</span>
                    {% endif %}
                </td>
                <td>
                    {% if book.is_active %}
                        <button type="button" class="btn btn-danger btn-active" data-active="1" data-book-id="{{ book.id }}">下架</button>
                    {% else %}
                        <button type="button" class="btn btn-success btn-active" data-active="0" data-book-id="{{ book.id }}">上架</button>
                    {% endif %}
                </td>
            </tr>
        {% endfor %}
      </tbody>
    </table>
    {{ pagination.links }}
{% endblock %}